<template>
    <el-table :loading="load" :data="tableList" :default-sort="{ prop: 'code', order: 'descending' }"
        style="width: 100%">
        <el-table-column prop="code" label="code" sortable width="180" />
        <el-table-column prop="name" label="Name" width="180" />
        <el-table-column prop="twoDayAgoOpen" label="twoDayAgoOpen" />
        <el-table-column prop="yesterdayOpen" label="yesterdayOpen" />
        <el-table-column prop="todayOpen" label="todayOpen" />
        <el-table-column prop="twoDayAgoClose" label="twoDayAgoClose" />
        <el-table-column prop="yesterdayClose" label="yesterdayClose" />
        <el-table-column prop="todayClose" label="todayClose" />
        
    </el-table>
    <el-pagination v-model:current-page="page" v-model:page-size="limit" :page-sizes="[20, 50, 100, 200, 300, 400]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            tableData: [],
            load: false,
            total: 0,
            page: 1,
            limit: 50,
            tableList: []
        }
    },
    methods: {
        getData() {
            this.load = true
            axios({
                url: '/api/signal/getRiseTrades',
                data: {
                    date: null
                },
                method: "GET"
            }).then(res => {
                if (res.data.code === 1) {
                    this.tableData = res.data.result
                    this.load = false
                    this.pageList()
                }
            })
        },
        //处理切换页码
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.limit = val;
            this.pageList();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.page = val;
            this.pageList();
        },
        // 分页
        pageList() {
            this.tableList = this.tableData.filter(
                (item, index) =>
                    index < this.page * this.limit &&
                    index >= this.limit * (this.page - 1)
            );
            this.total = this.tableData.length;
        },
    },
    mounted() {
        this.getData()
    }
}
</script>
